package com.xiaoxx.model.entity.webSocket;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.websocket.Session;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/***
 *   当前在线列表信息
 */
@Data
public class OnlineUser implements Serializable {
    private static final long serialVersionUID = 6239537958223115071L;
    /**
     * 用户ID
     */
    private String userId;
    /**
     * 用户名称
     */
    private String username;
    /**
     * 用户会话 (使用该对象进行消息发送)
     */
    private Session session;
    /**
     * 连接时间
     */
    private String createTime;

    @ApiModelProperty(value = "头像")
    private String headPic;

    /**
     * @param userId   用户id
     * @param session  用户session 回话信息
     */
    public OnlineUser(String userId, String username, Session session, String headPic) {
        this.userId = userId;
        this.username = username;
        this.session = session;
        this.headPic = headPic;
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        this.createTime = df.format(LocalDateTime.now());
    }
}
